//
//  EPMLeftTableView.m
//  myXianfeng
//
//  Created by 马继鵬 on 17/5/1.
//  Copyright © 2017年 EPM. All rights reserved.
//

#import "EPMLeftTableView.h"
#import "EPMCategoryModel.h"

@interface EPMLeftTableView()<UITableViewDataSource>



@property (weak,nonatomic) UIView* line;
@end
@implementation EPMLeftTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    if (self = [super initWithFrame:frame style:style]){
        [self setupUI];
    }
    return self;
}

#pragma mark - 设置tableView属性 -
- (void)setupUI{
    self.dataSource = self;
    self.delegate = self;
    self.rowHeight = 43;
    self.backgroundColor = lightBackColor;
    self.tableFooterView = [UIView new];
    [self registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self addLine];
   
    
}



#pragma mark - 数据 -

//- (NSArray*)catergeoryList{
//    if(_catergeoryList == nil){
//        _catergeoryList = @[@"热销榜",
//                              @"饮料酒水",
//                            @"休闲零食",
//                            @"牛奶面包",
//                            @"冰激凌",
//                            @"方便速食",
//                            @"粮油调料",
//                            @"生活用品"];
//    }
//    return _catergeoryList;
//}

#pragma mark - 数据源方法 -
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _MarketManger.catergoryList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
   
    EPMCategoryModel* model =  _MarketManger.catergoryList[indexPath.row];
    cell.textLabel.text = model.name;
    //选中颜色
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];
    //未选中颜色
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    [cell.textLabel setFont:[UIFont systemFontOfSize:15]];
    
    return cell;
}

#pragma mark - 添加指示 -

- (void)addLine{
    UIView* line = [[UIView alloc]init];
    self.line = line;
    line.backgroundColor = appColor;
    [self insertSubview:line atIndex:99];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo( self);
        make.width.mas_equalTo(5);
        make.height.mas_equalTo(self.rowHeight*4.0/5);
        make.top.equalTo(self).offset(self.rowHeight*0.1);
    }];
    
}

#pragma mark - 代理方法 -

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     [self.line mas_updateConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(self).offset(self.rowHeight*(0.1 + indexPath.row));
     }];
    
    [[NSNotificationCenter defaultCenter]postNotificationName:EPMMarketCatergoryDidChangedNotification object:nil userInfo:@{KCatergoryChanged:@(indexPath.row)}];
    
}




@end
